package ar.com.larreta.persistencia;

import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.SimpleExpression;

import com.extjs.gxt.ui.client.data.BaseFilterConfig;
import com.extjs.gxt.ui.client.data.BaseNumericFilterConfig;

public class AdaptadorBaseNumericFilterConfig implements AdaptadorFiltros {

	public static String LT = "LT";
	public static String GT = "GT";
	public static String EQ = "EQ";
	
	public SimpleExpression obtenerRestriccion(BaseFilterConfig filterConfig) {
		BaseNumericFilterConfig numericFilterConfig = (BaseNumericFilterConfig) filterConfig;
		if (LT.equalsIgnoreCase(numericFilterConfig.getComparison())){
			return Restrictions.lt(filterConfig.getField(), filterConfig.getValue());	
		}
		if (GT.equalsIgnoreCase(numericFilterConfig.getComparison())){
			return Restrictions.gt(filterConfig.getField(), filterConfig.getValue());
		}
		if (EQ.equalsIgnoreCase(numericFilterConfig.getComparison())){
			return Restrictions.eq(filterConfig.getField(), filterConfig.getValue());
		}
		return null;
	}

}
